package com.lll.demo.controller;
//只管接口接收数据

import com.alibaba.druid.util.StringUtils;
import com.lll.demo.entity.User;
import com.lll.demo.service.UserService;
import com.lll.demo.vo.UserVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@Controller
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    @ResponseBody
    @RequestMapping(value = "/register", method = RequestMethod.POST)
    public Map<String, Object> userRegister(@RequestBody UserVo userVo) {
        Map<String, Object> reData = new HashMap<>();

        // 在这里实现验证逻辑，比如查询数据库验证用户名和密码是否匹配
        if (StringUtils.isEmpty(userVo.getId()) || StringUtils.isEmpty(userVo.getPassword()) || StringUtils.isEmpty(userVo.getName())) {
            reData.put("message", "注册成功");
            reData.put("message", "注册失败，请检查用户名和密码");
            return  reData;
        } else {
            User user = new User(userVo);
            return userService.userRegist(user);

        }

    }
}
